package com.minshenglife.zanzan.pub;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Config {
		private static final Logger log = LoggerFactory.getLogger(Config.class);
		/**花落谁家中奖数量*/
		public static String BETTING_WINNUM="betting.winNum";
		/**微信专有标识符WX_APPID*/
		public static final String WX_APPID="WX_APPID";
		/**微信专有标识符WX_SECRET*/
		public static final String WX_SECRET="WX_SECRET";
		/**EMO微信专有标识符WX_APPID*/
		public static final String WX_EMO_APPID="WX_EMO_APPID";
		/**EMO微信专有标识符WX_SECRET*/
		public static final String WX_EMO_SECRET="WX_EMO_SECRET";
		/**赞赞 链接网页的根地址*/
		public static final  String WX_BASEURL="WX_BASEURL";
		
		private static Properties properties = null;
		
		static {
			try {
				properties = getConfigProperties("config.properties");
				try
				{
					Properties prop = getConfigProperties("common-config.properties");
					if(prop != null)
					{
						properties.putAll(prop);
					}
				}
				catch(Exception e)
				{
					log.error("init common-config.properties error: " + e.getMessage());
				}
				
			} catch (Exception e) {
				e.printStackTrace();
				log.error("init config.properties error: " + e.getMessage());
			}
		}
		/**
		 * 获取配置文件内容
		 * @param fileName
		 * @return
		 * @throws Exception
		 */
		private static Properties getConfigProperties(String fileName) throws Exception {
	        Properties properties = new Properties();
	        InputStream is = Config.class.getClassLoader().getResourceAsStream(fileName);
	        properties.load(is);
	        is.close();
	        return properties;
	    }
		/**
		 * 根据键值获取内容
		 * @param key
		 * @return
		 */
		public static String getProperty(String key,String defaultValue){
			try
			{
				return properties.getProperty(key,defaultValue);
			}
			catch(Exception e)
			{
				log.debug("get properties error:" + e.getMessage());
				return defaultValue;
			}
		}
		
		public static String getProperty(String key){
			return getProperty(key,"");
		}
	

}
